//
//  EditSettingCell.m
//  18Birdies
//
//  Created by Lc on 15/4/30.
//  Copyright (c) 2015年 Lc. All rights reserved.
//

#import "EditSettingCell.h"
#import "EditSettingCellData.h"
#import "LcFoundation.h"

@implementation EditSettingCell

- (void)postContruct {
  [super postContruct];
  [self.titleLabel setLcFont:[LcFont dr17]];
  self.textField.textColor = LC_COLOR_DARK;
  self.textField.tintColor = LC_COLOR_BLUE;

  [self.textField addTarget:self
                     action:@selector(textFieldChanged)
           forControlEvents:UIControlEventEditingChanged];
  [self.textField addTarget:self
                     action:@selector(textFieldChanged)
           forControlEvents:UIControlEventEditingDidEnd];
  [self.textField addTarget:self
                     action:@selector(textFieldChanged)
           forControlEvents:UIControlEventEditingDidEndOnExit];
}

- (void)textFieldChanged {
  LC_CHECK_NOT_NULL(self.cellData);
  EditSettingCellData* cellData = (EditSettingCellData*)self.cellData;
  if (cellData.contentMaxLimit > 0 && self.textField.text.length > cellData.contentMaxLimit) {
    NSString* str = self.textField.text;
    self.textField.text =
        [str substringToIndex:NSMaxRange([str
                                  rangeOfComposedCharacterSequenceAtIndex:cellData.contentMaxLimit -
                                                                          1])];
  }
  cellData.content = self.textField.text;
  self.placeHolderLabel.hidden = self.textField.text.length > 0;
}

@end
